/*
 * Stepper.cpp
 *
 *  Created on: Mar 6, 2011
 *      Author: Jason
 */
#include "stepper.h"

stepper::stepper(void)
{
}

//Pin assignment for the Enable control
void stepper::setupEn(byte port, byte bit)
{
	_enable.setup(port, bit, OUTPUT);
}

//Pin assignment for the Direction control
void stepper::setupDir(byte port, byte bit)
{
	_direction.setup(port, bit, OUTPUT);
}

//Pin assignment for the Step control
void stepper::setupStep(byte port, byte bit)
{
	_step.setup(port, bit, OUTPUT);
}

//Invert the Enable control line
void stepper::invertEn(state s)
{
	_enable.setInvert(s);
}

//Invert the Direction control line
void stepper::invertDir(state s)
{
	_direction.setInvert(s);
}

void stepper::set(stepperStatus v)
{
	switch(v)
	{

		case ENABLE:
			_enable.set();
			break;

		case DISABLE:
			_enable.clear();
			break;

		case FORWARD:
			_direction.set();
			break;

		case REVERSE:
			_direction.clear();
			break;
	}
}

state stepper::get(stepperStatus v)
{
	switch(v)
	{

		case ENABLE:
			return(_enable.get()==TRUE?TRUE:FALSE);

		case DISABLE:
			return(_enable.get()==FALSE?FALSE:TRUE);

		case FORWARD:
			return(_direction.get()==TRUE?TRUE:FALSE);

		case REVERSE:
			return(_direction.get()==FALSE?FALSE:TRUE);
	}
	return(FALSE);
}

void stepper::pulse(void)
{
	_step.set();
	_step.clear();
}

